package Stack;

import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Stack;

class MyQueueUsStack {

    public ArrayDeque<Integer> s1;
    public ArrayDeque<Integer> s2;
    public MyQueueUsStack() {
        s1 = new ArrayDeque<>();
        s2 = new ArrayDeque<>();
    }

    public void push(int x) {
        s1.push(x);
    }

    public int pop() {
        //2个栈都是空 意味着 队列为空
        if(empty()) {
            return -1;
        }
        if(s2.isEmpty()) {
            while (!s1.isEmpty()) {
                s2.push(s1.pop());
            }
        }
        return s2.pop();
    }

    public int peek() {
        if(empty()) {
            return -1;
        }
        if(s2.isEmpty()) {
            while (!s1.isEmpty()) {
                s2.push(s1.pop());
            }
        }
        return s2.peek();
    }

    /**
     * 判断 模拟实现的 队列 是否为空
     * @return
     */
    public boolean empty() {
        return s1.isEmpty() && s2.isEmpty();
    }
}
